#include <stdlib.h>
#include <math.h>

#include "hoc.h"
#include "hoc.tab.h"
#include "math.h"

static struct {
	char*	ptr_cname;
	double	dcval;
} consts[] = {
	{"PI",	  3.14159265358979323846},
	{"E",	  2.71828182845904523536},
	{"GAMMA", 0.57721566490153286060},	/* Euler */
	{"DEG",	 57.29577951308232087680},	/* Deg/Radian */
	{"PHI",	  1.61803398874989484820},	/* Golden Ratio */
	{NULL,	  0}
};

static struct {
	char*	ptr_cname;
	double	(*ptr_dfunc)(double);
} builtins[] = {
	{"sin",	  sin},
	{"cos",	  cos},
	{"atan",  atan},
	{"log",	  Log},		/* Check Args */
	{"log10", Log10},	/* Check Args */
	{"exp",	  Exp},		/* Check Args */
	{"sqrt",  Sqrt},	/* Check Args */
	{"int",	  integer},	/* Check Args */
	{"abs",	  fabs},
	{NULL,	  0}
};

/* Install constants and built-ins in table */
void init() {
	int i;
	Symbol_t* ptr_sym;

	for ( i = 0; consts[i].ptr_cname != NULL; i++ ) {
		install( consts[i].ptr_cname, VAR, consts[i].dcval );
	}

	for ( i = 0; builtins[i].ptr_cname != NULL; i++ ) {
		ptr_sym = install( builtins[i].ptr_cname, BLTIN, 0.0 );
		ptr_sym->u.ptr_dfunc = builtins[i].ptr_dfunc;
	}
}
